package com.compass.framework.manager


import com.compass.framework.constant.AFTER_SALE
import com.compass.framework.constant.DOCTOR_POSITION
import com.compass.framework.constant.DOCTOR_URGENCY_BACKLOG
import com.compass.framework.constant.INSPECTION_REPORT
import com.compass.framework.constant.MEDICAL_CONSULTATION_DOCTOR_STATUS
import com.compass.framework.constant.MEDICAL_CONSULTATION_STATUS
import com.compass.framework.constant.NOTIFICATION_TYPE
import com.compass.framework.constant.NURSE_PROJECT_TYPE
import com.compass.framework.constant.ORDER_CONSULTATION_TYPE
import com.compass.framework.constant.ORDER_INSPECTION_SOURCE
import com.compass.framework.constant.ORDER_NURSE_STATUS
import com.compass.framework.constant.ORDER_PRESCRIPTION_STATUS
import com.compass.framework.constant.PRESCRIPTION_CHANNEL
import com.compass.framework.constant.PRESCRIPTION_FREQUENCY
import com.compass.framework.constant.PRESCRIPTION_USAGE
import com.compass.framework.constant.WALLET_LOG_SOURCE
import com.compass.framework.constant.WALLET_LOG_TYPE
import com.compass.framework.ext.toBeanOrNull
import com.compass.framework.model.Dictionaries

import com.tencent.mmkv.MMKV

/**
 * Description： 管理医生一些字典信息/药品
 * Date:2023/12/27 17:40
 */
object DictionariesManager {

    private var mmkv = MMKV.defaultMMKV()

    /**
     *  保存会诊医生参与状态
     */
    fun saveParticipationStatus(usage: String?) {
        mmkv.encode(MEDICAL_CONSULTATION_DOCTOR_STATUS, usage)
    }

    /**
     * 获取用会诊医生参与状态
     */
    private  fun getParticipationStatus(): String? {
        return mmkv.decodeString(MEDICAL_CONSULTATION_DOCTOR_STATUS, "")
    }

    fun getParticipationStatusValue(key:String?):String{
        val list = getParticipationStatus()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }

    /**
     *  保存护理状态
     */
    fun saveNurseStatus(usage: String?) {
        mmkv.encode(ORDER_NURSE_STATUS, usage)
    }

    /**
     * 获取护理状态
     */
    private fun getNurseStatus(): String? {
        return mmkv.decodeString(ORDER_NURSE_STATUS, "")
    }

    fun getNurseStatusValue(key:String?):String{
        val list = getNurseStatus()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }






    /**
     *  保存护理售后状态
     */
    fun saveAfterStatus(usage: String?) {
        mmkv.encode(AFTER_SALE, usage)
    }

    private fun getAfterStatus(): String? {
        return mmkv.decodeString(AFTER_SALE, "")
    }

    fun getAfterStatusValue(key:String?):String{
        val list = getAfterStatus()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }



    /**
     *  保存护理标签
     */
    fun saveNurseProjectType(usage: String?) {
        mmkv.encode(NURSE_PROJECT_TYPE, usage)
    }

    /**
     * 获取护理标签
     */
    private  fun getNurseProjectType(): String? {
        return mmkv.decodeString(NURSE_PROJECT_TYPE, "")
    }

    fun getNurseProjectTypeValue(key:String?):String{
        val list = getNurseProjectType()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return "未知"
    }


    /**
     *  保存会诊状态
     */
    fun saveConsultationStatus(usage: String?) {
        mmkv.encode(MEDICAL_CONSULTATION_STATUS, usage)
    }

    /**
     * 获取用会诊状态
     */
    private fun getConsultationStatus(): String? {
        return mmkv.decodeString(MEDICAL_CONSULTATION_STATUS, "")
    }

    fun getConsultationStatusValue(key:String?):String{
        val list = getConsultationStatus()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    /**
     *  保存用法用量
     */
    fun savePrescriptionUsage(usage: String?) {
        mmkv.encode(PRESCRIPTION_USAGE, usage)
    }

    /**
     * 获取用法用量
     */
    fun getPrescriptionUsage(): String? {
        return mmkv.decodeString(PRESCRIPTION_USAGE, "")
    }

    fun getUsage(key:String?):String{
        val list = getPrescriptionUsage()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }

    /**
     *  处方订单状态字典
     */
    fun saveOrderStatus(status: String?) {
        mmkv.encode(ORDER_PRESCRIPTION_STATUS, status)
    }

    /**
     * 获取处方订单状态字典
     */
     fun getOrderStatusJson(): String? {
        return mmkv.decodeString(ORDER_PRESCRIPTION_STATUS, "")
    }

    fun getOrderStatus(key:String):String{
        val list = getOrderStatusJson()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }

    /**
     *  问诊类型
     */
    fun saveOrderConsultationType(status: String?) {
        mmkv.encode(ORDER_CONSULTATION_TYPE, status)
    }

    private fun getOrderConsultationType(): String? {
        return mmkv.decodeString(ORDER_CONSULTATION_TYPE, "")
    }

    fun getOrderConsultationTypeString(key:String):String{
        val list = getOrderConsultationType()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    /**
     *  钱包流水类型
     */
    fun saveWalletLogType(status: String?) {
        mmkv.encode(WALLET_LOG_TYPE, status)
    }

    private  fun getWalletLogType(): String? {
        return mmkv.decodeString(WALLET_LOG_TYPE, "")
    }

    fun getWalletLogTypeString(key:String):String{
        val list = getWalletLogType()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }

    /**
     *  钱包流水类型
     */
    fun saveWalletLogSource(status: String?) {
        mmkv.encode(WALLET_LOG_SOURCE, status)
    }

    private fun getWalletLogSource(): String? {
        return mmkv.decodeString(WALLET_LOG_SOURCE, "")
    }

    fun getWalletLogSourceSource(key:String):String{
        val list = getWalletLogSource()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    /**
     *  检验检查
     */
    fun saveOrderInspectionSource(status: String?) {
        mmkv.encode(ORDER_INSPECTION_SOURCE, status)
    }

    private fun getOrderInspectionSource(): String? {
        return mmkv.decodeString(ORDER_INSPECTION_SOURCE, "")
    }

    fun getOrderInspectionSourceString(key:String):String{
        val list = getOrderInspectionSource()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    /**
     *  通知类型
     */
    fun saveNotificationType(status: String?) {
        mmkv.encode(NOTIFICATION_TYPE, status)
    }

    private fun getNotificationTypeSource(): String? {
        return mmkv.decodeString(NOTIFICATION_TYPE, "")
    }

    fun getNotificationTypeString(key:String):String{
        val list = getNotificationTypeSource()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    /**
     *  保存急代办typeValue
     */
    fun saveDoctorUrgencyBacklogType(usage: String?) {
        mmkv.encode(DOCTOR_URGENCY_BACKLOG, usage)
    }

    /**
     * 获取急代办typeValue
     */
    fun getDoctorUrgencyBacklogType(): String? {
        return mmkv.decodeString(DOCTOR_URGENCY_BACKLOG, "")
    }


    /**
     *  保存给药频次
     */
    fun savePrescriptionFrequency(usage: String?) {
        mmkv.encode(PRESCRIPTION_FREQUENCY, usage)
    }

    /**
     * 获取给药频次
     */
    fun getPrescriptionFrequency(): String? {
        return mmkv.decodeString(PRESCRIPTION_FREQUENCY, "")
    }
    /**
     *  保存报告单
     */
    fun saveInspectionReportType(usage: String?) {
        mmkv.encode(INSPECTION_REPORT, usage)
    }

    /**
     * 获取报告单
     */
    fun getInspectionReportType(): String? {
        return mmkv.decodeString(INSPECTION_REPORT, "")
    }


    /**
     *  保存医生职称
     */
    fun saveDoctorPosition(usage: String?) {
        mmkv.encode(DOCTOR_POSITION, usage)
    }

    /**
     * 获取医生职称
     */
    fun getDoctorPosition(): String? {
        return mmkv.decodeString(DOCTOR_POSITION, "")
    }


    fun getFrequency(key:String):String{
        val list = getPrescriptionFrequency()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }

    /**
     *  保存给药途径
     */
    fun savePrescriptionChannel(usage: String?) {
        mmkv.encode(PRESCRIPTION_CHANNEL, usage)
    }

    /**
     * 获取给药途径
     */
    fun getPrescriptionChannel(): String? {
        return mmkv.decodeString(PRESCRIPTION_CHANNEL, "")
    }

    fun getChannel(key:String):String{
        val list = getPrescriptionChannel()?.toBeanOrNull<MutableList<Dictionaries>>()
        list?.let {
            for (item in list){
                if (item.value == key) return item.label
            }
        }
        return ""
    }


    fun clearInfo(){
        //清空这个就行
        mmkv.encode(DOCTOR_URGENCY_BACKLOG, "")
    }
}